﻿/**
 * Nombres reservados: TextFieldEvent_onSetFocus, TextFieldEvent_onKillFocus, TextFieldEvent_onChanged, más los mismos que EventDispatcherWrapper
 */
class TextFieldEvent {
	// auxiliary to not to get a compiler error.
	private var dispatchEvent, TextFieldEvent_onSetFocus, TextFieldEvent_onKillFocus,
	TextFieldEvent_onChanged:Function;
	
	public static function aplicar(receptor:TextField):TextField {
		// temp is an auxiliary to not to get a compiler error on some compilers that forces to asign new objects to a variable.
		var temp:TextFieldEvent = new TextFieldEvent(receptor);
		return receptor;
	}

	public function TextFieldEvent(receptor:TextField) {
		EventDispatcherWrapper.wrap(receptor);
		// Track original methods.
		receptor.TextFieldEvent_onSetFocus = receptor.onSetFocus;
		receptor.TextFieldEvent_onKillFocus = receptor.onKillFocus;
		receptor.TextFieldEvent_onChanged = receptor.onChanged;
		
		receptor.onSetFocus = setFocus_2;
		receptor.onKillFocus = killFocus_2;
		receptor.onChanged = changed_2;
	}

	private function setFocus_2():Void {
		//trace("onRollOver: " + this["ref"].dispatchEvent);
		//trace("onRollOver: " + (this["TextFieldEventDispatcher_ref"] instanceof TextFieldEventDispatcherWrapper));
		TextFieldEvent_onSetFocus();
		dispatchEvent({target: this, type: "setFocus"});
	}

	public function killFocus_2():Void {
		TextFieldEvent_onKillFocus();
		this.dispatchEvent({target: this, type: "killFocus"});
	}
	
	public function changed_2():Void {
		TextFieldEvent_onChanged();
		this.dispatchEvent({target: this, type: "changed"});
	}
}